home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 207 < prev    next >
Internet Message Format  |  1996-08-06  |  6KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c++,comp.lang.c,comp.std.c
  4. Subject: Re: Hungarian notation
  5. Date: Sat, 27 Jan 96 23:47:09 GMT
  6. Organization: none
  7. Message-ID: <822786429snz@genesis.demon.co.uk>
  8. References: <30C40F77.53B5@swsbbs.com> <JSA.96Jan26175507@organon.com> <31098190.8106176@nntp.ix.netcom.com> <4eco1g$aih@fountain.mindlink.net> <4ecqkn$p1t@solutions.solon.com> <4edore$sh1@fountain.mindlink.net>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <4edore$sh1@fountain.mindlink.net>
  15.            genew@mindlink.bc.ca "Gene Wirchenko" writes:
  16.  
  17. >seebs@solutions.solon.com (Peter Seebach) wrote:
  18.  
  19. >>However, given something where the *result* is implementation defined, I
  20. >>would expect that no unexpected *behavior* was allowed.
  21. >
  22. >     A result is a behavior, no?
  23.  
  24. Yes, but not all behaviours produce a result i.e. a value. A result is
  25. required in this case so not all behaviours are acceptable. The standard
  26. does not define the meaning of basic terms (it would probably be twice as
  27. thick if it tried to do so). For example an 'operator' is applied to one or
  28. more 'operands' to generate a 'result'. The operands and result are values.
  29.  
  30. >     Gah, the arguments over wording.  Next: "How many angel can dance
  31. >on the end of a C pointer?"
  32.  
  33. Indeed, wording is very important in standards!
  34.  
  35. >>>     Why are no side effects permitted?  Chapter and verse, please.
  36. >
  37. >>Because none are specified.  The semantics of the >> operator on signed
  38. >>ints are implementation specified (or is that defined?) but no one would
  39. >>tolerate it formatting disks, because it doesn't say it can, and the
  40. >>wording makes it clear that no extra behavior is expected.
  41. >
  42. >     Doesn't none specified mean that the implementation is free to
  43. >play hopscotch with nasal demons?
  44.  
  45. Only when no behaviour at all is specified. When any behaviour is specified
  46. the implementation is bound by that specification.
  47.  
  48. >>>     What if the conversion results in overflow?
  49.  
  50. This is precisely what can give an implementation defined result. If the
  51. conversion does *not* result in overflow then the standard defines the
  52. behaviour exactly (OK, floating point rounding is implementation-defined).
  53. In the case of overflow the semantics of the particular conversion being
  54. performed comes into play:
  55.  
  56. floating point -> floating point   - undefined behaviour (6.2.1.4)
  57. floating point -> any integer      - undefined behaviour (6.2.1.3)
  58. any integer    -> floating point   - undefined behaviour (6.2.1.3 by lack
  59.                                                           of definition)
  60. any integer    -> unsigned integer - defined by standard (6.2.1.2) in terms
  61.                                      of type limits. The type limits themselves
  62.                                      are implementation defined, although
  63.                                      constrained by the standard.
  64. any integer    -> signed integer   - implementation defined (6.2.1.2) result
  65.                                      i.e. the implementation must map the
  66.                                      result to a value that the target type
  67.                                      can represent and document how that is
  68.                                      determined.
  69.  
  70. >>This is actually a legitimate question; if conversion is taken to be
  71. >>an operation, then the previously pointed out limit on all arithmetic
  72. >>ops comes into play, and we have full-fleged *undefined behavior* -
  73. >>easily enough to format a disk with.
  74.  
  75. This presumably refers to 6.3 which says:
  76.  
  77. "If an exception occurs during the evaluation of an expression (that is,
  78.  if the result is not mathematically defined or not in the range of
  79.  representable values for its type), the behaviour is indefined."
  80.  
  81. In the last two conversion cases above the result is guaranteed to be
  82. a representable value (even if that value is implementation defined) so
  83. they don't invoke undefined behaviour. You need to make the distinction
  84. between the normal unbounded mathematical result and the actual result
  85. of the C conversion or operation. Unsigned integer arithmetic shows most
  86. graphically that these are not in general the same, e.g. UINT_MAX+1 is
  87. mathematically the value 1 greater than UINT_MAX but 0 in C.
  88.  
  89. >>>     If it is impossible to convert due to sizing, then the "must" is
  90. >>>rather silly, isn't it?
  91. >
  92. >>Not really; it must do *some* conversion, and the conversion must be the
  93. >>obvious one where that applies, and implementation-defined elsewhere.
  94. >
  95. >     My point is that if the value can't be represented then it's
  96. >hardly the case that a conversion is being performed.  If you consider
  97. >butchering a value to an implementation defined value to be
  98. >conversion, gah.
  99.  
  100. Certainly a conversion is being performed - you start with a value of
  101. one type and end up with a value of another type. The only thing of interest
  102. here is, given the initial value, the conversion being performed and the
  103. implementation definition, whether it should be possible to determine
  104. the exact value of the result (hence giving a proper mathematical
  105. function mapping) or whether the implementation could specify a
  106. 'random' result which could vary between identical conversions. The standard
  107. seems to permit the latter although I don't see any implementation/
  108. performance considerations resulting from requiring the former. The
  109. standard should say that implementation-defined behaviour is deterministic.
  110.  
  111. -- 
  112. -----------------------------------------
  113. Lawrence Kirby | fred@genesis.demon.co.uk
  114. Wilts, England | 70734.126@compuserve.com
  115. -----------------------------------------
  116.